Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
How to pass "parameter" to react component

I have a quick question, I am attempting to refactor my code in a existing codebase, this codebase uses a render function, however I would like to replace this with a react functional component instead.

However I am getting a error when I am passing in a parameter called "searchResults" which is a list.

Here is the previous non-refactored code

 searchResults.sort((a, b) => new Date(b[0].created) - new Date(a[0].created));

const Rows = [];

searchResults.forEach((appResults, i) => {
  Rows.push({
    cells: [
      appResults[0].applicationId,
      <>{renderSuccessCount(appResults)}</>,
      prettifyDate(appResults[0].created)
    ],
    isOpen: false
  });

This is my refactored code

 const newRows = [];

searchResults.forEach((appResults, i) => {
  newRows.push({
    cells: [
      appResults[0].applicationId,
     <SuccessCount>{appResults}={appResults}</SuccessCount>,
      prettifyDate(appResults[0].created)
    ],
    isOpen: false
  });

This is the function SuccessCount (in the non refactored code, renderSuccessCount was just renamed to SuccessCount in the refactored version

    const SuccessCount = (appResults: AppResult[]) => {
    const nSuccesses = appResults.filter((result: AppResult) => result.pulseStatus === SUCCESS).length;
    return Something;
  };

My question is relatively simple how do I pass appResults into my functional component, my current refactored code gives me this error

TS2740: Type '{ children: any[]; }' is missing the following properties from type 'AppResult[]': length, pop, push, concat, and 26 more.

This is in the linter, how do I get rid of it?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Now that SuccessCount is not a regular function but a react functional component, it'll not receive regular arguments. You'll have to access them via props

const SuccessCount = ({appResults}: {appResults: AppResult[]}) => {

Same as

const SuccessCount = (props) => {
const {appResults} = props; // or const appResults = props.appResults;
}

Usage as functional component

<SuccessCount appResults={appResults} />
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda